package com.kefu.exam.controller;

import com.kefu.common.mybatis.Order;
import com.kefu.exam.model.ExamPaperSubject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.common.annotation.Permission;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.common.vo.DeleteVo;
import com.kefu.common.vo.DetailVo;
import com.kefu.exam.model.ExamPaper;
import com.kefu.exam.service.ExamPaperService;
import com.kefu.exam.vo.ExamPaperSearchVo;
import com.kefu.exam.vo.ExamPaperInsertVo;
import com.kefu.exam.vo.ExamPaperUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import java.util.Map;

/**
 * @author xy
 * @date 2022/02/28
 */
@Api(tags = "考卷表")
@RestController
@RequestMapping("exam/paper")
public class ExamPaperController extends AbstractBaseController {

    @Autowired
    private ExamPaperService examPaperService;

    @PostMapping("/add")
    @ApiOperation(value = "添加问卷", notes = "添加问卷")
    public Result<String> add(@Validated @RequestBody ExamPaperInsertVo examPaperVo) {
    	logger.info("添加问卷:{}", examPaperVo);
        return ResultGenerator.genSuccessResult(examPaperService.addPager(examPaperVo));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除考卷表", notes = "删除考卷表")
    public Result<String> delete(@Validated @RequestBody DeleteVo delete) {
    	logger.info("删除考卷表:{}", delete);
        return ResultGenerator.genSuccessResult(examPaperService.deletePaper(delete.getId()));
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改考卷表", notes = "修改考卷表")
    public Result<String> update(@Validated @RequestBody ExamPaperUpdateVo examPaperVo) {
    	logger.info("修改考卷表:{}", examPaperVo);
    	
        return ResultGenerator.genSuccessResult(examPaperService.updatePaper(examPaperVo));
    }

    @PostMapping("/detail")
    @ApiOperation(value = "考卷表详情", notes = "考卷表详情")
    public Result<ExamPaper> detail(@Validated @RequestBody DetailVo detail) {
        logger.info("考卷表查看详情:{}", detail);
        
        return ResultGenerator.genSuccessResult(examPaperService.findById(detail.getId()));
    }

    @PostMapping("/detailProblem")
    @ApiOperation(value = "考卷表问题", notes = "考卷表问题")
    public Result<Map<String,Object>> detailProblem(@Validated @RequestBody ExamPaperSearchVo detailProblem) {
        logger.info("考卷表查看详情:{}", detailProblem);
        return ResultGenerator.genSuccessResult(examPaperService.findByIdAndSort(detailProblem.getPaperId()));
    }


    @PostMapping("/list")
    @ApiOperation(value = "查询考卷表", notes = "查询考卷表")
    public Result<Page<ExamPaper>> list(@Validated @RequestBody ExamPaperSearchVo search) {
        logger.info("查询考卷表:{}", search);

        Page<ExamPaper> page = examPaperService.searchLambdaPage(search);
        return ResultGenerator.genSuccessResult(page);
    }

}
